<template>
  <div class="home-sale-card">
    <div class="sale-card-header">
      <span class="title">我的客户</span>
      <span class="app-link noline" @click="gotoAll">全部<i class="el-icon-arrow-right" /></span>
    </div>
    <div class="mycustomer-card-content">
      <el-scrollbar class="" style="height:278px">
        <NoData v-if="List.length<=0" height="40" />
        <div v-for="l in List" :key="l.id" class="my-customer-item">
          <div class="item-top">
            <img src="@/assets/images/icon-user.png">
            <span class="app-link" @click="gotoMainPage('customer/info', { id: l.id })">{{ l.name }}</span>
          </div>
          <!-- <div class="item-row">
            <span class="row-title">发货国家/地区：</span>
            <span class="row-input">12121</span>
          </div> -->
          <div class="item-row">
            <span class="row-title">客户类型：</span>
            <span class="row-input">{{ getEnumText(customerTypes,l.type) }}</span>
          </div>
          <div class="item-row">
            <span class="row-title">客户级别：</span>
            <span class="row-input">{{ getEnumText(customerLevels,l.level) }}</span>
          </div>
          <div class="item-row">
            <span class="row-title">收货地址：</span>
            <span class="row-input">{{ formatAddress(l) }}</span>
          </div>
          <!-- <div class="item-row">
            <span class="row-title">电话：</span>
            <span class="row-input">{{ l.phone }}</span>
          </div> -->
        </div>

      </el-scrollbar>
    </div>

  </div>
</template>
<script>
import { customerLevels, getEnumText, customerTypes } from '@/utils/enums'
import { getCustomerListHome } from '@/api/customer'
export default {
  name: 'SaleCard',
  data() {
    return {
      customerTypes,
      customerLevels,
      date: 7,
      List: []
    }
  },
  mounted() {
    const owner = this.USER.userName || ''
    getCustomerListHome({ currentPage: 1, pageSize: 3, owner: owner }).then(res => {
      this.List = res.records || []
    })
  },
  methods: {
    getEnumText,
    gotoAll() {
      // setParams({ searchStatus: '2' })
      this.gotoMainPage('customer', { searchStatus: '2' })
    },
    formatAddress(l) {
      if (l.receiveList && l.receiveList.length > 0) {
        const address = l.receiveList[0]
        const addr = `${address.province || ''}${address.city || ''}${address.county || ''}${address.address || ''}`
        return addr
      }
      return ''
    }

  }
}
</script>
